﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

namespace XLDL
{
    public class XL_DS_DaXem : DataTable
    {
        public XL_DS_DaXem()
        {
         DataColumn colMs = this.Columns.Add("ID", Type.GetType("System.Int32"));
        colMs.AutoIncrement = true;
        colMs.AutoIncrementStep = 1;
        colMs.AutoIncrementSeed = 1;
        this.Columns.Add("hinh_anh", Type.GetType("System.String"));
        this.Columns.Add("link", Type.GetType("System.String"));
        }
        public void kiemtra(string hinh)
        {
            if (this.Rows.Count != 0)
            {
                for (int i = 0; i < this.Rows.Count; i++)
                {
                    if (this.Rows[i]["hinh_anh"].ToString() == hinh)
                    {
                        this.Rows.RemoveAt(i);
                        break;
                    }
                }
            }

           
                if (this.Rows.Count == 5)
                {
                    this.Rows.RemoveAt(0);
                }
           
            
        }
        public void them(string hinh,string link)
        {
            if (this.Rows.Count < 5)
            {
                if (link.Contains("p=") == true)
                {
                    link = link.Remove(link.LastIndexOf("&"));
                }
                DataRow dong_moi = this.NewRow();
                dong_moi["hinh_anh"] = hinh;
                dong_moi["link"] = link;
                this.Rows.Add(dong_moi);
                this.AcceptChanges();
            }
        }
        public string xuat()
        {
            StringBuilder str = new StringBuilder();

            //<a href="http://www.dynamicdrive.com/style/" rel="balloon1">Dynamic Drive CSS Library</a><br /><br />

    
            str.Append("<table cellpadding='0' cellspacing='2' border='0px' class='his' style=' background:#fff;'>");
            if (this.Rows.Count != 0)
            {
                str.Append("<tr><td valign='top' align='center' style=' background:#55BE47;'><b>Đã xem</b></td></tr>");
                
               for (int i = this.Rows.Count-1; i>=0 ; i--)
                {
                    str.Append("<tr><td valign='top'><a href='"+this.Rows[i]["link"].ToString()+"'><img src='images/" + this.Rows[i]["hinh_anh"].ToString() + "' width='50px' border='0px'/></a></td></tr>");
                 }
               
            }
            str.Append("</table>");
           
            return str.ToString();
        }
    }
}
